package com.whsxt.controller;

import com.github.pagehelper.PageInfo;
import com.whsxt.common.AjaxResult;
import com.whsxt.domain.Return;
import com.whsxt.dto.ReturnDto;
import com.whsxt.service.ReturnService;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.apache.shiro.authz.annotation.RequiresRoles;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.Arrays;

@RequestMapping("/return")
@RestController
@RequiresRoles(value = {"admin","business","user", "devops"}, logical = Logical.OR)
public class ReturnController {

    @Autowired
    private ReturnService returnService;
    /**
     * 查询分页的还车记录数据
     * @param returnDto
     * @return
     */
    @RequestMapping("/findByPage.do")
    public AjaxResult findByPage(ReturnDto returnDto){
        PageInfo<Return> returnPageInfo = returnService.select(returnDto);
        return AjaxResult.ok(returnPageInfo);
    }

    /**
     * 删除还车数据接口
     * @param id
     * @return
     */
    @RequestMapping("/delete.do")
    @RequiresPermissions("return:delete")
    public AjaxResult delete(Integer[] id){
        boolean isOk = returnService.batchDelete(Arrays.asList(id));
        return isOk ? AjaxResult.ok() : AjaxResult.error("删除数据失败");
    }

    /**
     * 清空还车记录的接口
     * @return
     */
    @RequestMapping("/clear.do")
    @RequiresPermissions("return:delete")
    public AjaxResult clear(){
        boolean isOk = returnService.clear();
        return isOk ? AjaxResult.ok() : AjaxResult.error("清空数据失败");
    }
}
